package hxm.monads;

/**
 * A monad for working with arrays.
 * 
 * @author Simon Krajewski
 */

@unify("Iterable")
class ArrayMonad
{
	static public function bind<A, B>(a:Array<A>, f:A -> Array<B>):Array<B>
	{
		if (a == null) return [];
		var ret = new Array();
		for (li in a)
			for (e in f(li))
				ret.push(e);
		return ret;
	}

	inline static public function yield<A>(a:A):Array<A> return [a]

	public static var zero:Array<Dynamic> = [];
}